﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace client
{
    class GestorSerialize
    {
        private string path = "./certificados/utilizador.txt";

         /// <summary>
        /// Load
        /// </summary>
        public Utilizador Load(Utilizador util)
        {

            Utilizador novo = new Utilizador();
            
            XmlSerializer serializer = new XmlSerializer(util.GetType());
            using (FileStream readFileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                object obj = serializer.Deserialize(readFileStream);
                novo = (Utilizador)obj;
                readFileStream.Close();
                return novo;
                 //raffleCouponClient = ((ConfigRaffle)obj)._raffleCouponClient;
                 //raffleCoupon = ((ConfigRaffle)obj)._raffleCoupon;
                
            }
        }
 
        /// <summary>
        /// Save
        /// </summary>
        public void Save(Utilizador util)
        {
            
            XmlSerializer serializer = new XmlSerializer(util.GetType());
            using (TextWriter writeFileStream = new StreamWriter(path))
            {
                serializer.Serialize(writeFileStream, util);
                writeFileStream.Close();
            }
        }
    }
}
